// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
//申明请求对象
const templateIndexRequest = {

    //defect请求的基本url
    BASE_URL: confing.QC_URL + "/templateIndex",

    /**
        * 保存常见缺陷信息
        * @param {*} templateIndex 
        * @param {*} callback 
        */
    save(templateIndex, callback) {
        console.log(templateIndex + "======");
        request.post(this.BASE_URL + '/save', templateIndex, callback);
    },

    /**
        * 编辑缺陷信息
        * @param {*} templateIndex 
        * @param {*} callback 
        */
    update(templateIndex, callback) {
        if (templateIndex != undefined && templateIndex.indexCode != undefined) {
            request.post(this.BASE_URL + "/update", templateIndex, callback);
        }
    },
    /**
        * 根据indexCode加载常见缺陷信息
        * @param {*} templateCode 
        * @param {*} callback 
     */
    get(templateCode, callback) {
        if (templateCode) {
            let url = this.BASE_URL + "/get?templateCode=" + templateCode;
            request.get(url, callback);
        }
    },
    getEdit(indexCode, callback) {
        if (indexCode) {
            let url = this.BASE_URL + "/get?indexCode=" + indexCode;
            request.get(url, callback);
        }
    },
    /**
      * 根据indexCode删除常见缺陷信息
      * @param {*} indexCode 
      * @param {*} callback 
    */
    delete(indexId, callback) {
        if (indexId) {
            let url = this.BASE_URL + "/delete?indexId=" + indexId;
            request.delete(url, callback);
        }
    },



    //请求的API
    list(page = 1, limit = 10, templateIndex1, callback) {
        //url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit + "&templateIndex1=" + templateIndex1;

        //发送请求
        request.get(url, callback);

    }
}

//将defectRequest暴漏出去
export default templateIndexRequest;
